var listtext = ['选项一', '选项二', '选项三']
var score = null
var value = ''
var bizhongValue = ''
var successarr = ["C", "B", "A"];
function checkboxList() {
    $.ajax({
        type: "get",
        url: "js/package.json",
        success: function (data) {
            if (data.code == 10000) {
                console.log(data.result, '---')
                if (data.result.length > 0) {
                    var html = ``;
                    $.each(data.result, function (index, item) {
                        totality = `${item.questionNo}`
                        if (item.questionType == 0) {
                            html += `<div class='swiper-slide slide${index}'><h3 class="h3">${item.questionContent}</h3><ul class='list radioList'>`
                            $.each(item.questionOptions, function (index, data) {
                                html += `<li><span>${data.optionContent}</span></li>`
                            })

                        }
                        html += `</ul></div>`
                        $('.swiper-wrapper').empty().append(html)
                        $('.swiper-container').each(function (i, val) {
                            var self = $(this);
                            // self.find('.radio-list').find('li').click(function () {
                            //     $(this).find('input:radio').prop('checked', true);
                            // })
                            console.log('9990000')
                            self.find('.radioList').find('li').click(function () {
                                $(this).addClass("active").siblings().removeClass('active')
                            })
                        })
                    })
                }
                mySwiper.init()
            }
        }

    })
}

checkboxList()
var total
// 切换造轮子
var mySwiper = new Swiper('.swiper-container', {
    // observer: true,
    autoHeight: true,
    init: false,
    pagination: {
        el: '.swiper-pagination',
        type: 'fraction',
    },
    navigation: {
        hideOnClick: true,
        hiddenClass: 'my-button-hidden',
        // nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
    },

});
var arrayList = []
$('#btn2').click(function () {
	console.log($('.swiper-slide-active').is('.slide0'), 'pppp')
//	if($('.swiper-slide-active').is('.slide0')){
//		$('#main').css("background-image","url(images/img2.jpg)")
//	}else if($('.swiper-slide-active').is('.slide1')){
//		$('#main').css("background-image","url(images/img3.jpg)")
//	}else if($('.swiper-slide-active').is('.slide2')){
//		$('#main').css("background-image","url(images/img4.jpg)")
//	}
    var val = $('.swiper-slide-active .three-list li').hasClass('active') || $('.swiper-slide-active .radioList li').hasClass('active') || $(".swiper-slide-active .checkbox-list li input[type='checkbox']").is(':checked');
    if (!val) {
        alert('请选择选项')
        return false
    } else {
        mySwiper.slideNext();
        var list = $(".swiper-slide-prev .active")
        console.log(list, 'list');
        console.log(mySwiper.activeIndex, 'index')
        if(mySwiper.activeIndex){
            var arrayList = []
        	for (let i = 0; i < list.length; i++) {
                arrayList.push(list[i].innerText.charAt(0))
            }
        }
        console.log(arrayList, '*/*///')
    }
    if (mySwiper.isEnd) {
        $('.buttonNext .default').hide()
        $('.buttonNext .submit').show()
    }
})
$('.swiper-button-prev').click(function () {
    $('.buttonNext .default').show()
    $('.buttonNext .submit').hide()
})

function layer() {
    $('.chooseFixed').show()
    tabWin()
}

$('.chooseFixed .chooseWrap .titleText .close').click(function () {
    if (bizhongValue == '' || bizhongValue == null) {
        alert('还有完全选择好，就这样离开了')
    }
    var text = value + '#' + bizhongValue
    if (bizhongValue != '' && bizhongValue != undefined) {
        if ($.inArray(text, listtext) < 0) {
            $('.three-list').empty()
            listtext.unshift(text)
            listtext.pop()
            for (let i = 0; i < listtext.length; i++) {
                if (i < 3) {

                    $('.three-list').append(`<li onclick="layer()" class="threelistIcon active"><span>${listtext[i]}</span></li>`)
                }
            }
            mySwiper.updateAutoHeight();
        } else {
            alert('您已经选择了相同的内容')
        }
    }
    $('.chooseFixed ').slideUp()
    $(".chooseFixed .chooseWrap .tab li:last-child").removeClass('cur')
    $(".chooseFixed .chooseWrap .divTabInfo ul:last-child").removeClass('on')
    $(".chooseFixed .chooseWrap .tab li:first-child").addClass('cur')
    $(".chooseFixed .chooseWrap .divTabInfo ul:first-child").addClass('on')
    // tabWin()
})

function tabWin() {
    value = ''
    bizhongValue = ''
    $(".chooseFixed .chooseWrap .tab ").on('click', 'li', function () {
        console.log('888')
        if (value == null || value == '') {
            // alert('请选择一项投向内容')
            return false
        }
        $(".chooseFixed .chooseWrap .tab li").eq($(this).index()).addClass("cur").siblings().removeClass('cur');
        $(".divTabInfo ul").removeClass('on').eq($(this).index()).addClass('on');
    });
}

$(".chooseFixed .chooseWrap .divTabInfo .touxiang").on("click", "li", function () {
    $(this).addClass("enable").siblings().removeClass('enable');
    value = $(this).html()
})
$(".chooseFixed .chooseWrap .divTabInfo .bizhong").on("click", "li", function () {
    $(this).addClass("enable").siblings().removeClass('enable');
    bizhongValue = $(this).html()
})

function reCheck(item) {
    console.log(item, 'item')
    $('.three-list').empty();
    var htmls = `<ul class='list three-list'>`;
    for (var i = 0; i < listtext.length; i++) {
        if (i < 3) {
            htmls += `<li class ='threelistIcon' onclick="layer()">${listtext[i]}</li>`
        }
    }
    // htmls += '</ul></div>'
    $.each(item, function (index, data) {
        if (data.optionType == 1) {
            $('.bizhong').append(`<li>${data.optionContent}</li>`)
        } else if (data.optionType == 0) {
            $('.touxiang').append(`<li>${data.optionContent}</li>`)
        }
    })
    return htmls
}

$('.submit').click(function () {
    var val = $('.swiper-slide-active .three-list li').hasClass('active') || $('.swiper-slide-active .radioList li').hasClass('active') || $(".swiper-slide-active .checkbox-list li input[type='checkbox']").is(':checked');
    if (!val) {
        alert('请选择选项')
        return false
    } else {
    	 var list = $(".active")
        var arr = []
        for (let i = 0; i < list.length; i++) {
            arr.push(list[i].innerText.charAt(0))
        }
    }
	if(arr === successarr){
		alert('恭喜你，全部答对啦！')
		window.location.href = 'new.html'
	}else{
		alert('很遗憾，有错误哦~')
		window.location.href = 'new.html'
	}
   
})

function clickChecked(obj) {
    if (obj.checked) {
        console.log('7788')
        obj.parentNode.className = "active"
    } else {
        obj.parentNode.className = ""
    }
}

function arrayList() {

}